package com.example.pinkcat.api.getData;

import android.annotation.SuppressLint;
import android.content.Context;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.Adapter;
import android.widget.Toast;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.manager.RequestManagerTreeNode;
import com.example.pinkcat.activity.api.ApiService;
import com.example.pinkcat.activity.api.entity.ResponsEntity_boolean;
import com.example.pinkcat.activity.api.entity.ResponsEntity_videoinfo;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.example.pinkcat.adapter.Dongtai_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Fenqu_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Fenqu_qm_adapter;
import com.example.pinkcat.adapter.GallerView_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Remen_FragmentPagerAdapter;
import com.example.pinkcat.adapter.Tougao_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Wode_FankeepAdapter;
import com.example.pinkcat.adapter.Yingshi_1_RecycykerViewAdapter;
import com.example.pinkcat.adapter.Yingshi_2_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Zhuifan_m1_RecyclerViewAdapter;
import com.example.pinkcat.adapter.Zhuifan_m2_RecyclerViewAdapter;
import com.example.pinkcat.api.ApiServer;
import com.example.pinkcat.activity.api.entity.ResponsEntity_video;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;
import com.example.pinkcat.api.entity.ContributeEntity;
import com.example.pinkcat.api.entity.ContributeStaticMsg;
import com.example.pinkcat.api.entity.ContributeVideoEntity;
import com.example.pinkcat.api.entity.FanKeepStaticMsg;
import com.example.pinkcat.api.entity.Fankeep;
import com.example.pinkcat.api.entity.ResponsEntity_VideoInfoEntity;
import com.example.pinkcat.api.entity.ResponsEntity_fankeep;
import com.example.pinkcat.api.entity.ResponsEntity_videomsg;
import com.example.pinkcat.api.entity.Respons_ContributeEntity;
import com.example.pinkcat.api.entity.Respons_ContributeVideoEntity;
import com.example.pinkcat.api.entity.VideoInfoEntity;
import com.example.pinkcat.api.entity.VideowaibuEntity;
import com.example.pinkcat.api.entity.myCollectStaticMsg;
import com.example.pinkcat.api.entity.videoMsg;
import com.example.pinkcat.client.Client;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class getData_waibu<T> {
    static String uri = "http://119.91.218.197:8888/";
    // static String uri="http://4218.197:8089/";

    //获取轮播图
    public static void getbannervideo(Context context, GallerView_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getbannervideo(userStaticMsg.userId);//发送请求


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    System.out.println(jsonStr);
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.addBannerData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取视频
    public static void getrecommendVideoByuser(Context context, GallerView_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getrecommendVideoByuser(userStaticMsg.userId);//发送请求


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
//                        System.out.println(ra.getData().size() + "reafffffffffffffffffff");
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.addData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }


    //获取视频2
    public static void getVideo_new(Context context, GallerView_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getrecommendVideoByuser(userStaticMsg.userId);//发送请求


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.addData_new(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取日排行
    public static void getdayhot(Context context, Remen_FragmentPagerAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getdayhot();//发送请求
        String style = "day";

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.setData(v_list, style);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取周排行

    public static void getweeekhot(Context context, Remen_FragmentPagerAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getweekday();//发送请求
        String style = "week";

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.setData(v_list, style);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取分区类型
    public static void getVideotype(Context context, Fenqu_qm_adapter adapter, String type) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getVideoType(type);//发送请求
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list = ra.getData();
                        adapter.addData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }



    //获取粉丝 关注 动态
    public static boolean getkeep(Context context, String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create(ApiServer.class);
        Call<ResponseBody> call;
        if (user_id.equals("-1")) return false;
        call = apiServer.getkeep(user_id);//发送请求



        //同步请求
        try {
            Response<ResponseBody> response = call.execute();
            ResponseBody responseBody = response.body();
            if (responseBody == null) {
                Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse", response.body().toString());
                //转化json字符串
                String jsonStr = responseBody.string();
                Gson gson = new Gson();
                ResponsEntity_fankeep ra = gson.fromJson(jsonStr, ResponsEntity_fankeep.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getCode() == 200) {
                    FanKeepStaticMsg.moving = ra.getData().getMoving();
                    FanKeepStaticMsg.fan = ra.getData().getKeep();
                    FanKeepStaticMsg.keep = ra.getData().getFan();
                    return true;
                } else {
                    Toast.makeText(context, ra.getMsg(), Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
        }
        return false;
    }


    //获取追番轮播图
    public static void getZhuifanBanner(Context context, Zhuifan_m2_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getdayhot();//发送请求

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode() == 200) {
                        List<VideowaibuEntity> v_list = new ArrayList<>();
                        for (VideowaibuEntity v : ra.getData()){
                            if (v.getVideo_type().equals("动漫")){
                                v_list.add(v);
                            }
                        }
                        adapter.addBannerData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //根据动漫(视频类型)视频获取视频

    public static void getZhuifanvideo(Context context, Zhuifan_m2_RecyclerViewAdapter adapter,String type) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getVideoType(type);//发送请求

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size() > 0) {
                        List<VideowaibuEntity> v_list =new ArrayList<>();
                        for (VideowaibuEntity v : ra.getData()){
                            if (v.getVideo_type().equals("动漫")){
                                v_list.add(v);
                            }
                        }
                        adapter.addData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取影视轮播图
    public static void getYingshiBanner(Context context, Yingshi_1_RecycykerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        call = apiServer.getdayhot();//发送请求

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200) {
                        List<VideowaibuEntity> v_list = new ArrayList<>();
                        for (VideowaibuEntity v :ra.getData()){
                            if (v.getVideo_type().equals("电视剧")|| v.getVideo_type().equals("电影")||v.getVideo_type().equals("综艺")){
                                v_list.add(v);
                            }
                        }
                        adapter.addBannerData(v_list);

                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //根据影视(视频类型:电视剧、电影、综艺)视频获取视频
    public static void getYingshivideo(Context context, Yingshi_1_RecycykerViewAdapter adapter,List<String> list_type) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;
        for (String type :list_type){
            if (type.equals("电视剧")){
                call = apiServer.getVideoType(type);//发送请求
                //异步请求
                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        ResponseBody responseBody = response.body();
                        if (responseBody == null) {
                            Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        try {
                            Log.e("onResponse", response.body().toString());
                            //转化json字符串
                            String jsonStr = responseBody.string();
                            Gson gson = new Gson();
                            ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                            if (ra.getCode()==200) {
                                List<VideowaibuEntity> v_list =new ArrayList<>();
                                for (VideowaibuEntity v: ra.getData()) {
                                    if (v.getVideo_type().equals("综艺") || v.getVideo_type().equals("电视剧") || v.getVideo_type().equals("电影")) {
                                        v_list.add(v);
                                    }
                                }
                                adapter.addData(v_list);
                                /**数据获取**/

                            } else {
                                Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }
            if (type.equals("电影")){
                call = apiServer.getVideoType(type);//发送请求
                //异步请求
                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        ResponseBody responseBody = response.body();
                        if (responseBody == null) {
                            Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        try {
                            Log.e("onResponse", response.body().toString());
                            //转化json字符串
                            String jsonStr = responseBody.string();
                            Gson gson = new Gson();
                            ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                            if (ra.getCode()==200) {
                                List<VideowaibuEntity> v_list =new ArrayList<>();
                                for (VideowaibuEntity v: ra.getData()) {
                                    if (v.getVideo_type().equals("综艺") || v.getVideo_type().equals("电视剧") || v.getVideo_type().equals("电影")) {
                                        v_list.add(v);
                                    }
                                }
                                adapter.addData(v_list);
                                /**数据获取**/

                            } else {
                                Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }
            if (type.equals("综艺")){
                call = apiServer.getVideoType(type);//发送请求
                //异步请求
                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        ResponseBody responseBody = response.body();
                        if (responseBody == null) {
                            Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        try {
                            Log.e("onResponse", response.body().toString());
                            //转化json字符串
                            String jsonStr = responseBody.string();
                            Gson gson = new Gson();
                            ResponsEntity_videomsg ra = gson.fromJson(jsonStr, ResponsEntity_videomsg.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                            if (ra.getCode()==200) {
                                List<VideowaibuEntity> v_list =new ArrayList<>();
                                for (VideowaibuEntity v: ra.getData()) {
                                    if (v.getVideo_type().equals("综艺") || v.getVideo_type().equals("电视剧") || v.getVideo_type().equals("电影")) {
                                        v_list.add(v);
                                    }
                                }
                                adapter.addData(v_list);
                                /**数据获取**/

                            } else {
                                Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }


    }


    //根据用户获取动态
    public static void getActivity(Context context, Dongtai_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;

        call = apiServer.getActivity(userStaticMsg.userId);//发送请求
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_VideoInfoEntity ra = gson.fromJson(jsonStr, ResponsEntity_VideoInfoEntity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size()>0) {
                        List<VideoInfoEntity> v_list = ra.getData();
                        System.out.println(jsonStr + " 65565555555655555555");
                        adapter.addData(v_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                        System.out.println(" no Data  pppppppppppppppppppppppppppppppp");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //动态页点赞 喜欢
    @SuppressLint("SetTextI18n")
    public static boolean video_like__un(Context context,String video_id,String clikeType) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        switch (clikeType){
            case "like":call = apiService.likevideo(userStaticMsg.userId,video_id);break;
            case "unlike":call = apiService.unlickvideo(userStaticMsg.userId,video_id);break;
            default:Toast.makeText(context,"未知操作",Toast.LENGTH_SHORT).show();return false;
        }
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class);//把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
                Toast.makeText(context," ",Toast.LENGTH_SHORT).show();
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }


    //获取投稿页用户的粉丝、视频播放、评论数量、点赞数量
    public static boolean getContribute(Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create(ApiServer.class);
        Call<ResponseBody> call;
        call = apiServer.getContribute(userStaticMsg.userId);
        //同步请求
        try {
            Response<ResponseBody> response = call.execute();
            ResponseBody responseBody = response.body();
            if (responseBody == null) {
                Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse", response.body().toString());
                //转化json字符串
                String jsonStr = responseBody.string();
                Gson gson = new Gson();
                System.out.println(jsonStr +"555555555555555555555555555");
                Respons_ContributeEntity ra = gson.fromJson(jsonStr,  Respons_ContributeEntity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getCode() == 200) {
                    ContributeStaticMsg.comment_num = ra.getData().getComment_num();
                    ContributeStaticMsg.fans_num = ra.getData().getFans_num();
                    ContributeStaticMsg.like_num = ra.getData().getLike_num();
                    ContributeStaticMsg.video_play_num = ra.getData().getVideo_play_num();

                    return true;
                } else if (ra.getCode() == 500){
                    ContributeStaticMsg.comment_num = "0";
                    ContributeStaticMsg.fans_num = "0";
                    ContributeStaticMsg.like_num = "0";
                    ContributeStaticMsg.video_play_num = "0";

                    return true;
                }else {
                    Toast.makeText(context, ra.getMsg(), Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取投稿页用户投稿视频
    public static void getContributeVideo(Context context, Tougao_RecyclerViewAdapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiServer apiServer = retrofit.create((ApiServer.class));
        Call<ResponseBody> call;

        call = apiServer.getContributeVideo(userStaticMsg.userId);//发送请求
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    System.out.println(jsonStr + " 66666666666666666666666666666666");
                    Gson gson = new Gson();
                    Respons_ContributeVideoEntity ra = gson.fromJson(jsonStr, Respons_ContributeVideoEntity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size()>0) {
                        System.out.println(ra.getData().size() + " 6666666666666666666666666666666666");
                        //根据上传时间升序排序
                        Collections.sort(ra.getData(), new Comparator<ContributeVideoEntity>() {
                            @Override
                            public int compare(ContributeVideoEntity o1, ContributeVideoEntity o2) {
                                    return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                            }
                        });
                        List<ContributeVideoEntity> c_list = ra.getData();
                        adapter.setVideoData(c_list);
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取投稿页用户视频信息

    public static void getContributeVideoMsg(Context context,  Tougao_RecyclerViewAdapter adapter,String video_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService = retrofit.create((ApiService.class));
        Call<ResponseBody> call;

        call = apiService.getpalyvideo(video_id,userStaticMsg.userId);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody = response.body();
                if (responseBody == null) {
                    Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse", response.body().toString());
                    //转化json字符串
                    String jsonStr = responseBody.string();
                    Gson gson = new Gson();
                    ResponsEntity_videoinfo ra=gson.fromJson(jsonStr, ResponsEntity_videoinfo.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode() == 200) {
                        adapter.setvideoinfoData(ra.getData());
                        /**数据获取**/

                    } else {
                        Toast.makeText(context, "没有数据", Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }


    //获取我的追剧(追番)
    public static void getMyVideo(Context context, Zhuifan_m1_RecyclerViewAdapter adapter, int type, String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1"))
        {
            Toast.makeText(context,"未登陆",Toast.LENGTH_SHORT).show();
            return ;
        }
        call = apiService.getmyfollowvideo(user_id);



        //同步请求
        try {
            Response<ResponseBody> response = call.execute();
            ResponseBody responseBody = response.body();
            if (responseBody == null) {
                Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                Log.e("onResponse", response.body().toString());
                //转化json字符串
                String jsonStr = responseBody.string();
                Gson gson = new Gson();
                ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getCode() == 200) {
                    //按时间排序
                        Collections.sort(ra.getData(), new Comparator<VideoEntity>() {
                            public int compare(VideoEntity o1, VideoEntity o2) {
                                return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                            }
                        });
                       // Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        List<VideoEntity> videoEntities=new ArrayList<>();
                        if (type==0){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("动漫")){
                                    videoEntities.add(v);
                                }
                            }
                        }else if (type==1){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("综艺")||v.getVideo_type().equals("电视剧")||v.getVideo_type().equals("电影")){
                                    videoEntities.add(v);
                                }
                            }
                        }
                        myCollectStaticMsg.mycollect_zf=videoEntities.size();
                        adapter.setData(videoEntities);
                }else {
                    Toast.makeText(context, ra.getMsg(), Toast.LENGTH_SHORT).show();
                    return;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
        }
    }

    //获取我的影视(影视)
    public static void getMyVideo_ys(Context context, Yingshi_2_RecyclerViewAdapter adapter, int type, String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService = retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1")) {
            Toast.makeText(context, "未登陆", Toast.LENGTH_SHORT).show();
            return;
        }
        call = apiService.getmyfollowvideo(user_id);

//        //异步请求
//        call.enqueue(new Callback<ResponseBody>() {
//            @Override
//            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                ResponseBody responseBody =response.body();
//                if (responseBody==null){
//                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                try {
//                    Log.e("onResponse",response.body().toString());
//                    //转化json字符串
//                    String jsonStr=responseBody.string();
//                    Gson gson= new Gson();
//                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
//                    if (ra.getCode()==200){
//                        //按时间排序
//                        Collections.sort(ra.getData(), new Comparator<VideoEntity>() {
//                            public int compare(VideoEntity o1, VideoEntity o2) {
//                                return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
//                            }
//                        });
//                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
//                        List<VideoEntity> videoEntities=new ArrayList<>();
//                        if (type==0){
//                            for (VideoEntity v: ra.getData()){
//                                if (v.getVideo_type().equals("动漫")){
//                                    videoEntities.add(v);
//                                }
//                            }
//                        }else if (type==1){
//                            for (VideoEntity v: ra.getData()){
//                                if (v.getVideo_type().equals("综艺")||v.getVideo_type().equals("电视剧")||v.getVideo_type().equals("电影")){
//                                    videoEntities.add(v);
//                                }
//                            }
//                        }
//                        myCollectStaticMsg.mycollect_ys = videoEntities.size();
//                        adapter.setData(videoEntities);
//                    }
//                    else {
//                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
//                    }
//
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public void onFailure(Call<ResponseBody> call, Throwable t) {
//                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
//            }
//        });
//    }

        //同步请求
        try {
            Response<ResponseBody> response = call.execute();
            ResponseBody responseBody = response.body();
            if (responseBody == null) {
                Toast.makeText(context, "内部服务器错误", Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                Log.e("onResponse", response.body().toString());
                //转化json字符串
                String jsonStr = responseBody.string();
                Gson gson = new Gson();
                ResponsEntity_video ra = gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getCode() == 200) {
                    //按时间排序
                    Collections.sort(ra.getData(), new Comparator<VideoEntity>() {
                        public int compare(VideoEntity o1, VideoEntity o2) {
                            return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                        }
                    });
                    //Toast.makeText(context, ra.getMsg(), Toast.LENGTH_SHORT).show();
                    List<VideoEntity> videoEntities = new ArrayList<>();
                    if (type == 0) {
                        for (VideoEntity v : ra.getData()) {
                            if (v.getVideo_type().equals("动漫")) {
                                videoEntities.add(v);
                            }
                        }
                    } else if (type == 1) {
                        for (VideoEntity v : ra.getData()) {
                            if (v.getVideo_type().equals("综艺") || v.getVideo_type().equals("电视剧") || v.getVideo_type().equals("电影")) {
                                videoEntities.add(v);
                            }
                        }
                    }
                    myCollectStaticMsg.mycollect_ys = videoEntities.size();
                    adapter.setData(videoEntities);
                } else {
                    Toast.makeText(context, ra.getMsg(), Toast.LENGTH_SHORT).show();
                    return;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "网络异常", Toast.LENGTH_SHORT).show();
        }

    }

}
